
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--    <meta charset=utf-8">-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>数据库后台</title>
    <!-- BOOTSTRAP STYLES-->
<!--    <link href="../css/bootstrap.css" rel="stylesheet" />-->
    <link href="../css/bootstrap.min.css" rel="stylesheet" />
    <!-- CUSTOM STYLES-->
    <link href="../css/custom.css" rel="stylesheet" />
    <!-- /. WRAPPER  -->
    <!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
    <!-- JQUERY SCRIPTS -->
    <script src="../js/jquery-1.7.1.min.js"></script>
    <!-- BOOTSTRAP SCRIPTS -->
    <script src="../js/bootstrap.min.js"></script>
    <!-- METISMENU SCRIPTS -->
    <script src="../js/jquery.js"></script>

    <script type="text/javascript" src="../js/bootstrap.min.js"charset="UTF-8"></script>
    <script src="../js/common.js"></script>
</head>

<body>
<div id="wrapper">

    <nav class="navbar navbar-default navbar-cls-top " role="navigation"
         style="margin-bottom: 0">
        <div class="navbar-header">
            <a class="navbar-brand">用户管理</a>
        </div>
        <div style="color: white; padding: 15px 50px 5px 50px; float: right; font-size: 16px;">
<!--            <form action="../loginOut.jsp" method="post">-->
                <button id = "loginout" class="btn btn-danger">注销</button>
<!--            </form>-->
        </div>
    </nav>
    <!-- /. NAV TOP  -->
    <nav class="navbar-default navbar-side" role="navigation">
        <div class="sidebar-collapse">
            <ul class="nav" id="main-menu">
                <li><a href="formsubmit.html"><i class="fa fa-qrcode fa-3x"></i>
                                    表单录入</a></li>
                <li><a href="distribute.html"><i
                        class="fa fa-bar-chart-o fa-3x"></i> 任务分配</a></li>
                <li><a href="feedback.html"><i
                        class="fa fa-bar-chart-o fa-3x"></i> 数据反馈</a></li>
                <li><a href="usermanage.html"><i
                        class="fa fa-bar-chart-o fa-3x"></i> 用户管理</a></li>

                <li><a href="searchlist.html"><i
                        class="fa fa-bar-chart-o fa-3x"></i> 数据查询</a></li>

            </ul>

        </div>

    </nav>
    <!-- /. NAV SIDE  -->
    <div id="page-wrapper">
        <div id="page-inner">
            <div style="display: none"><input type="text" id="levelofuser"></div>
            <div class="container">
                <fieldset>
                    <legend>用户管理</legend>




                    <div class="container">
                        <div class="row clearfix">
                            <div class="col-md-2 column">
                                <input type="button" id="searchlist" class="btn btn-primary" value="查找" />
                                <input type="button" id="adduser" class="btn btn-primary" value="新增" />
                            </div>


                            <div id="adduserform" style="display: none">
                            <div class="col-md-3 column">
                                <div class="form-group">
                                    <div class="col-md-4 column">
                                        <label for="newuser">用户名</label>
                                    </div>
                                    <div class="col-md-8 column">
                                        <input type="text" class="form-control" id="newuser" />
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 column">
                                <div class="col-md-4 column">
                                    <label for="newpassword">密码</label>
                                </div>
                                <div class="col-md-8 column">
                                    <input type="password" class="form-control" id="newpassword" />
                                </div>
                            </div>
                             <div class="col-md-3 column">
                                    <div class="form-group">
                                        <div class="col-md-4 column">
                                            <label for="newname">真实姓名</label>
                                        </div>
                                        <div class="col-md-8 column">
                                            <input type="text" class="form-control" id="newname" />
                                        </div>
                                    </div>
                              </div>
                            <div class="col-md-1 column">
                                <button id="saveadduser" class="btn btn-default">提交</button>
                            </div>
                        </div>
                        </div>


                    </div>




                    <div class="row" style="padding: 50px 20px 0px 20px">

                        <div class="table-responsive">
                            <table class="table table-striped" id="table1"
                                   style="text-align: center">
                                <thead>
                                <td>用户名</td>
                                <td>密码</td>
                                <td>真实姓名</td>
                                <td>等级</td>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                        </div>
                    </div>
                </fieldset>
            </div>
            <!-- /. PAGE INNER  -->
        </div>
        <!-- /. PAGE WRAPPER  -->
    </div>

<!--    <script type="text/javascript" src="../js/AjaxAPI.js" charset="UTF-8"></script>-->
<!--    <script src="../js/jquery.dataTables.js"></script>-->
</div>
    <script type="text/javascript">
        $(document).ready(function () {


            $("#searchlist").click(function () {
                let d1 = {
                    temp:"temp",
                };
                $.ajax({
                    type: "POST",
                    url: "../login/searchUserlist",
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(d1),
                    dataType: "json",
                    success: function (data) {
                        if (data == null) {
                            // window.location.href = "/msgtable/html/login.html"
                            alert("无权限")
                        } else {
                            $('table tbody').html('');
                            $.each(data, function (i, item) {
                                // alert(item.userName)
                                // var _len = $("#tab tr").length;
                                var rowmsg="<tr id= align='center'>"
                                + "<td>" + item.userName + "</td>"
                                + "<td>" + item.password + "</td>"
                                + "<td>" + item.realName + "</td>";
                                if(item.rank!=null){ rowmsg=rowmsg+ "<td>" + item.rank + "</td>"}
                                rowmsg=rowmsg + "</tr>";
                                $("#table1").append(rowmsg);

                            })
                        }
                    },
                    error: function (data) {
                        window.location.href = "/msgtable/html/login.html"
                        alert("请登录")
                    }
                });
            });


            $("#adduser").click(function () {
                $("#adduserform").show();
            });


            $("#saveadduser").click(function () {
                if (!$("#newuser").val().length==0&&!$("#newpassword").val().length==0&&!$("#newname").val().length==0) {
                    let d1 = {
                        userName: $("#newuser").val(),
                        password: $("#newpassword").val(),
                        realName: $("#newname").val(),
                    };
                    $.ajax({
                        type: "POST",
                        url: "../login/Adduser",
                        contentType: "application/json;charset=utf-8",
                        data:JSON.stringify(d1),
                        dataType: "text",
                        success:function (data) {
                            alert(data)
                               $("#newuser").val("");
                               $("#newpassword").val("");
                               $("#newname").val("");
                        },
                        error:function (data) {
                            alert(data)
                        }
                    });

                }else {
                    alert("请输入账号或者密码")
                }



                $("#adduserform").hide();
            });


        });
    </script>

</body>
</html>